<?php

class CustomHttpRequest extends CHttpRequest
{

    /**
     * This is more sensistive getUserHostAddress() function then in CHttpRequest
     *
     * @return string
     */
    public function getUserHostAddress()
    {
        if (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP'] != '') {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != '') {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
            $ip = parent::getUserHostAddress();
        }
        $ip_array = explode(",", $ip);
        $ip = $ip_array[0];

        return $ip;
    }

    /**
     * Примитивное определение IP пользователя
     *
     * @return string
     */
    public function getSimpleUserHostAddress()
    {
        return isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : '127.0.0.1';
    }
}
